package com.manydatabase.Impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.manydatabase.entity.Agent;
import com.manydatabase.entity.Agent2;
import com.manydatabase.mapper.mapper1.AgentMapper;
import com.manydatabase.mapper.mapper2.Agent2Mapper;
import com.manydatabase.service.AgentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhanggq
 * @since 2019-10-20
 */
@Service
public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements AgentService {

    @Autowired
    private AgentMapper agentMapper;

    @Autowired
    private Agent2Mapper agent2Mapper;

    //    @Transactional(transactionManager = "primaryTransactionManager")
    @Override
    public void add(Agent agent) {
        agentMapper.add(agent);
    }

    @Override
    public Agent query() {
        return agentMapper.query();
    }

    @Override
//    @Transactional(rollbackFor = Exception.class, transactionManager = "secondTransactionManager")
//    @Transactional(rollbackFor = Exception.class, transactionManager = "primaryTransactionManager")
    public void addAgent2() {
        Agent2 agent2 = new Agent2();
        Agent query = agentMapper.query();
        BeanUtils.copyProperties(query, agent2);
        agent2Mapper.add(agent2);
        query.setName("newName");
        query.setId(String.valueOf(Integer.valueOf(query.getId()) + 1));
        agentMapper.add(query);
    }
}
